package com.stu.student_back_end.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stu.student_back_end.common.Constants;
import com.stu.student_back_end.common.Result;
import com.stu.student_back_end.controller.dto.PageDTO;
import com.stu.student_back_end.entity.TblNoHere;
import com.stu.student_back_end.service.ITblNoHereService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * noHere controller层接口
 */
@RestController
public class NoHereController {

    @Autowired
    private ITblNoHereService noHereService;

    /**
     * 分页查询
     * @param pageDTO
     * @return
     */
    @PostMapping("/n/query")
    public Result queryNoHerePage(@RequestBody PageDTO pageDTO) {
        return Result.success(noHereService.queryNoHerePage(pageDTO));
    }

    /**
     * 添加记录
     * @param noHere
     * @return
     */
    @PostMapping("/n/save")
    public Result saveNoHere(@RequestBody TblNoHere noHere) {
        boolean save = noHereService.save(noHere);

        if(!save) return Result.error(Constants.CODE_500,"添加失败！");

        return Result.success("添加成功！");
    }

    /**
     * 根据名称查找记录
     * @param name
     * @return
     */
    @PostMapping("/n/queryNoHere/{name}")
    public Result queryByName(@RequestBody PageDTO pageDTO, @PathVariable("name") String name) {
        Page<TblNoHere> page = noHereService.queryByNameNoHere(pageDTO, name);

        if(page == null) return Result.error(Constants.CODE_401,"数据为空");

        return Result.success(page);
    }
}
